import java.util.*;
import static java.lang.System.*;

public class ReshetoDivisors {
	public static void main(String[] args) {
		if (args.length == 2) {
			int a = Integer.parseInt(args[0]);
			int b = Integer.parseInt(args[1]);
			if (haveCommonDivisors(a, b))
				out.println(a + " and " + b + " have common divisors");
		} else {
			err.println("2 integer args required");
		}
	}

	static boolean haveCommonDivisors(long a, long b) {
		long M = Math.max(a, b), m = Math.min(a, b);
		long[] resheto = new long[(int)M + 2];
		long i, j;

		resheto[1] = 1;
		for (i = 2; i <= m; i++) {
			if (resheto[(int)i] == 0)
				for (j = i; j <= M; j += i)
					resheto[(int)j] = i;
			if (resheto[(int)m] == resheto[(int)M]) {
				err.println("resheto: " + Arrays.toString(resheto));
				return true;
			}
		}
		err.println("resheto: " + Arrays.toString(resheto));
		return false;
	}
}
